<template>
  <div class="base-container" id="main">
    <t-space direction="vertical">
      <t-form labelAlign="top" ref="form" :data="formData" :rules="rules" class="step-form table-form"
              labelWidth="140px">
        <t-row>
          <t-col :span="2" class="title"><span class="require">*</span>年度</t-col>
          <t-col :span="2">
            <t-form-item label="年度" name="year">
              <t-select clearable v-model="formData.year" :options="yearOption" />
            </t-form-item>
          </t-col>
        </t-row>
      </t-form>
      <t-row>
        <t-col :span="1"></t-col>
        <t-col :span="10">
          <t-table
            rowKey="index"
            :data="data"
            :columns="columns"
            stripe
            table-layout="auto"
            size="small"
            hover
            tableLayout="fixed"
            bordered
            cellEmptyContent="-"
          >
            <template #name="{row}">
              <p :class="row.class">{{ row.name }}</p>
            </template>
            <template #num="{row}">
              <!-- :disabled="preData.inputDisabled.includes(row.num)" -->
              <t-input-number v-if="row.num !== ''" min="0" size="large" v-model="formData[`${row.num}`]"></t-input-number>
            </template>
            <template #footerSummary>
              <div class="t-table__row-filter-inner">
                说明：1. 主要平衡关系：KH030≥KH0301
                <br/>      2. 填报单位组织的科普活动，参加的活动不在统计范围内。
                <br/>      3. 多主办单位的活动由第一主办单位填报。如果第一填报单位不在调查统计范围内的，可以由第二主办单位填报，以此类推。
              </div>
            </template>
          </t-table>
        </t-col>
        <t-col :span="1"></t-col>
      </t-row>
      <t-row style="margin-top: 20px;text-align: center">
        <t-col :span="12">
          <t-space :size="10">
            <t-button v-if="!isUpdate" theme="primary" :loading="applyLoading" @click="onSubmit(1)">{{
                applyLoading ? '提交中...' : '暂存'
              }}
            </t-button>
            <t-button v-if="!isUpdate" theme="primary" :loading="applyLoading" @click="onSubmit(2)">{{
                applyLoading ? '提交中...' : '提交'
              }}
            </t-button>
            <t-button v-if="isUpdate" theme="default" :loading="applyLoading" @click="onSubmit(3)">{{
                '取消'
              }}
            </t-button>
            <t-button v-if="isUpdate" theme="primary" :loading="applyLoading" @click="onSubmit(4)">{{
                applyLoading ? '修改中...' : '确认'
              }}
            </t-button>
          </t-space>
        </t-col>
      </t-row>
    </t-space>
  </div>
</template>

<script>
import { VITE_FILE_DOMAIN } from '@/api/upload'
export default {
  name: "events-add-edit",
  dicts: [],
  components: {
  },
  data() {
    return {
      yearOption: [],
      file_domain: VITE_FILE_DOMAIN,
      deptMenuOptions: [],
      columns: [
        // { colKey: 'index', title: '序号', width: '100' },
        { colKey: 'name', title: '指标名称', },
        { colKey: 'code', title: '代码', align: "center" },
        { colKey: 'jldw', title: '计量单位', align: "center"},
        { colKey: 'num', title: '数量', align: "center"},
      ],
      rules: {
        projectName: [
          {
            required: true,
            message: "项目名称不能为空",
          }
        ],
      },
      data: [],
      preData: {
        name: [
          '一、科普（技）讲座',
          '1.当年线下举办次数',
          '当年线下参加人次',
          '2.当年线上举办次数',
          '当年线上参加人次',
          '二、科普（技）展览',
          '1.当年专题展览线下举办次数',
          '当年线下参加人次',
          '2.当年专题展览线上举办次数',
          '当年线上参加人次',
          '三、科普（技）竞赛',
          '1.当年线下举办次数',
          '当年线下参加人次',
          '2.当年线上举办次数',
          '当年线上参加人次',
          '四、科普国际交流',
          '1.当年线下举办次数',
          '当年线下参加人次',
          '2.当年线上举办次数',
          '当年线上参加人次',
          '五、青少年科普',
          '1.青少年科技兴趣小组',
          '当年成立个数',
          '当年参加人次',
          '2.科技夏（冬）令营',
          '当年举办次数',
          '当年参加人次',
          '3.青少年主题科普活动',
          '当年举办次数',
          '当年参加人次',
          '六、老年人科普',
          '1.当年科普主题活动举办次数',
          '2.当年参加人次',
          '七、科技活动周',
          '1.科普专题活动线下举办次数',
          '线下参加人次',
          '2.科普专题活动线上举办次数',
          '线上参加人次',
          '八、大学、科研机构向社会开放',
          '1.当年开放单位个数',
          '2.当年参观人次',
          '九、当年举办实用技术培训次数',
          '当年参加人次',
          '十、当年重大科普活动次数',
          '十一、科普研发',
          '当年获批市级及以上科普项目数量',
          '其中：当年获批省、部级及以上科普项目数量',
        ],
        code:[
          '—',
          '次',
          '人次',
          '次',
          '人次',
          '—',
          '次',
          '人次',
          '次',
          '人次',
          '—',
          '次',
          '人次',
          '次',
          '人次',
          '—',
          '次',
          '人次',
          '次',
          '人次',
          '—',
          '—',
          '个',
          '人次',
          '—',
          '次',
          '人次',
          '—',
          '次',
          '人次',
          '—',
          '次',
          '人次',
          '—',
          '次',
          '人次',
          '次',
          '人次',
          '—',
          '个',
          '人次',
          '次',
          '人次',
          '次',
          '—',
          '项',
          '项',
        ],
        jldw: [
          '—',
          'KH110',
          'KH120',
          'KH130',
          'KH140',
          '—',
          'KH210',
          'KH220',
          'KH230',
          'KH240',
          '—',
          'KH310',
          'KH320',
          'KH330',
          'KH340',
          '—',
          'KH410',
          'KH420',
          'KH430',
          'KH440',
          '—',
          '—',
          'KH511',
          'KH512',
          '—',
          'KH521',
          'KH522',
          '—',
          'KH531',
          'KH532',
          '—',
          'KH010',
          'KH020',
          '—',
          'KH610',
          'KH620',
          'KH630',
          'KH640',
          '—',
          'KH710',
          'KH720',
          'KH810',
          'KH820',
          'KH900',
          '—',
          'KH030',
          'KH0301',
        ],
        num: [
          '',
          'kpjzxxcs',
          'kpjzxxcjrs',
          'kpjzxscs',
          'kpjzxscjrs',
          '',
          'kpzlxxcs',
          'kpzlxxcjrs',
          'kpzlxscs',
          'kpzlxscjrs',
          '',
          'kpjsxxcs',
          'kpjsxxcjrs',
          'kpjsxscs',
          'kpjsxscjrs',
          '',
          'kpjlxxcs',
          'kpjlxxcjrs',
          'kpjlxscs',
          'kpjlxscjrs',
          '',
          '',
          'qsnkjxq',
          'qsnkjxqcjs',
          '',
          'kjxly',
          'kjxlycjs',
          '',
          'qsnztkphd',
          'qsnztkphdcjs',
          '',
          'kpzthdjbcs',
          'kpzthdcjrs',
          '',
          'kpzthdxxjbcs',
          'kpzthdxxcjrs',
          'kpzthdxsjbcs',
          'kpzthdxscjrs',
          '',
          'kyjgkfgs',
          'kyjgcgrs',
          'syjspxcs',
          'syjspxcjrs',
          'zdkphdcs',
          '',
          'hpsjyskps',
          'hpsbyskps',
        ],
        class: [
          '',
          'indent2',
          'indent3',
          'indent2',
          'indent3',
          '',
          'indent2',
          'indent3',
          'indent2',
          'indent3',
          '',
          'indent2',
          'indent3',
          'indent2',
          'indent3',
          '',
          'indent2',
          'indent3',
          'indent2',
          'indent3',
          '',
          'indent2',
          'indent3',
          'indent3',
          'indent2',
          'indent3',
          'indent3',
          '',
          'indent2',
          'indent2',
          '',
          'indent2',
          'indent2',
          '',
          'indent2',
          'indent3',
          'indent2',
          'indent3',
          '',
          'indent2',
          'indent2',
          '',
          'indent2',
          '',
          '',
          'indent2',
          'indent2',
        ],
        inputDisabled: []
      },
      applyLoading: false,
      formData: {
        localId: '',
        year: new Date().getFullYear(),
        kpjzxxcs: 0,
        kpjzxxcjrs: 0,
        kpjzxscs: 0,
        kpjzxscjrs: 0,
        kpzlxxcs: 0,
        kpzlxxcjrs: 0,
        kpzlxscs: 0,
        kpzlxscjrs: 0,
        kpjsxxcs: 0,
        kpjsxxcjrs: 0,
        kpjsxscs: 0,
        kpjsxscjrs: 0,
        kpjlxxcs: 0,
        kpjlxxcjrs: 0,
        kpjlxscs: 0,
        kpjlxscjrs: 0,
        qsnkjxq: 0,
        qsnkjxqcjs: 0,
        kjxly: 0,
        kjxlycjs: 0,
        qsnztkphd: 0,
        qsnztkphdcjs: 0,
        kpzthdjbcs: 0,
        kpzthdcjrs: 0,
        kpzthdxxjbcs: 0,
        kpzthdxxcjrs: 0,
        kpzthdxsjbcs: 0,
        kpzthdxscjrs: 0,
        kyjgkfgs: 0,
        kyjgcgrs: 0,
        syjspxcs: 0,
        syjspxcjrs: 0,
        zdkphdcs: 0,
        hpsjyskps: 0,
        hpsbyskps: 0,
      },
      isUpdate: false,
    }
  },
  created() {
    for (let i = 2030; i >= 2000; i--) {
      this.yearOption.push({key: i, label: i.toString(), value: i.toString()})
    }
    const taskId = this.$route.params && this.$route.params.taskId;
    this.isUpdate = this.$route.query.isUpdate === 'true'
    Object.assign(this.formData, this.$route.query.currentRow)
    if (!taskId) {
      this.$message.error("缺少id");
      this.close();
      return false;
    }
    this.formData.localId = taskId

    for (let i = 0; i < this.preData.name.length; i++) {
      this.data.push({
        index: i + 1,
        name: this.preData.name[i],
        code: this.preData.code[i],
        jldw: this.preData.jldw[i],
        num: this.preData.num[i],
        class: this.preData.class[i]
      })
    }
  },
  methods: {
    onSubmit(type) {
      if (!this.formData.year) {
        this.$message.error('请选择年份！');
        return
      }
      if (type === 1) {
        this.$api.kpzh.events.add(this.formData).then(res => {
          this.$message.success('暂存成功！');
          this.$tab.closeOpenPage({path: this.$route.meta.activeMenu || "/kpzh/events/events-my"});
        })
      } else if (type === 2) {
        this.$api.kpzh.events.submit(this.formData).then(res => {
          this.$message.success('提交成功！');
          this.$tab.closeOpenPage({path: this.$route.meta.activeMenu || "/kpzh/events/events-my"});
        })
      } else if (type === 3) {
        this.$tab.closeOpenPage({path: this.$route.meta.activeMenu || "/kpzh/events/events-my"});
      } else if (type === 4) {
        this.$api.kpzh.events.update(this.formData).then(res => {
          this.$message.success('修改成功！');
          this.$tab.closeOpenPage({path: this.$route.meta.activeMenu || "/kpzh/events/events-my"});
        })
      } else {
        this.$message.error('type错误！');
      }
    },
    close() {
      this.$tab.closeOpenPage({path: "/kpzh/events/events-my"});
    }
  }
}
</script>

<style lang="less" scoped>
/deep/ .t-table__empty {
  min-height: initial;
}

</style>
